package com.guigu.controller.stock;


import com.github.pagehelper.PageInfo;
import com.guigu.pojo.design.DFile;
import com.guigu.pojo.stock.SThirdProductArea;
import com.guigu.pojo.stock.SWarehouseSetting;
import com.guigu.service.design.DFileService;
import com.guigu.service.stock.SThirdProductAreaService;
import com.guigu.service.stock.SWarehouseSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-25
 */
@Controller
@RequestMapping("/s-warehouse-setting")
public class SWarehouseSettingController {

    @Autowired
    private SWarehouseSettingService sWarehouseSettingService;

    @Autowired
    private DFileService dFileService;

    @Autowired
    private SThirdProductAreaService sThirdProductAreaService;

    //库房属性设置
    @GetMapping("/storeHouse")
    public String storeHouse(){
        return "jsp/stock/a/set_storehouse";
    }

    @GetMapping("/initialStoreHouseTbl")
    @ResponseBody
    public PageInfo<SWarehouseSetting> selectSoreHouse(){
        PageInfo<SWarehouseSetting> sWarehouseSettingPageInfo
                = sWarehouseSettingService.selectSwarehouseSetting();
        return sWarehouseSettingPageInfo;
    }

    //获取库房名称
    @PostMapping("/getWarehouseName")
    @ResponseBody
    public SWarehouseSetting getWarehouseName(@RequestBody String productId){
        //根据产品编号查询产品表
        DFile dFile = dFileService.selectByProductId(productId);
        //得到三级分类的id
        String thirdKindId = dFile.getThirdKindId();

        SThirdProductArea sThirdProductArea = sThirdProductAreaService.selectOne(thirdKindId);
        String warehouseId = sThirdProductArea.getWarehouseId();
        SWarehouseSetting swarehouse = sWarehouseSettingService.getWarehouseName(warehouseId);
        return swarehouse;
    }
}

